package com.jinzhi.jzweb.service.impl.moduleConfig;

import com.jinzhi.common.base.CoreServiceImpl;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.dao.ExaminationQuestionsComDao;
import com.jinzhi.jzweb.domain.ExaminationQuestionsComDO;
import com.jinzhi.jzweb.service.moduleConfig.ExaminationQuestionsComService;
import org.springframework.stereotype.Service;

@Service
public class ExaminationQuestionsComServiceImpl extends CoreServiceImpl<ExaminationQuestionsComDao, ExaminationQuestionsComDO> implements ExaminationQuestionsComService {


    /**
     * 新增试卷试题
     * @param examinationQuestionsComDO
     * @return
     */
    @Override
    public Result<?> addQuestions(ExaminationQuestionsComDO examinationQuestionsComDO) {
        if(null == examinationQuestionsComDO.getEpaperId()){
            return Result.fail("请先选择试卷！");
        }
        if(null == examinationQuestionsComDO.getType()){
            return Result.fail("请选择题目类型！");
        }
        if(null == examinationQuestionsComDO.getIntroduce()){
            return Result.fail("请输入题目描述！");
        }
        if(null == examinationQuestionsComDO.getOptions()){
            return Result.fail("请输入题目选项！");
        }
        if(null == examinationQuestionsComDO.getAnswers()){
            return Result.fail("请输入题目答案！");
        }
        boolean flag = this.insert(examinationQuestionsComDO);
        if(flag){
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    /**
     * 删除试卷
     * @param examinationQuestionsComDO
     * @return
     */
    @Override
    public Result<?> deleteQuestions(ExaminationQuestionsComDO examinationQuestionsComDO) {
        if(null==examinationQuestionsComDO.getId()){
            return Result.fail("请先选择要删除的数据！");
        }
        boolean b = this.deleteById(examinationQuestionsComDO.getId());
        if(b){
            return Result.ok();
        } else {
            return Result.fail();
        }
    }
}
